<template>
    <IContent :spinShow="loading">
        <ISearch v-model="search">
            <FormItem label="订单号" >
                <Input size="small" type="textarea" v-model="search.order_number" style="width: 300px;" :rows="4"></Input>
            </FormItem>
            <FormItem label="仓单号">
                <Input size="small" type="textarea" v-model="search.order_code" style="width: 300px;" :rows="4"></Input>
            </FormItem>
            <FormItem :label-width="1">
                <Button type="primary" icon="ios-search" @click="getLists(1)" size="small">搜索</Button>
            </FormItem>
            <Row>
                <FormItem label="清关状态">
                    <RadioGroup v-model="search.status" type="button" size="small">
                        <Radio label="">全部</Radio>
                        <Radio label="0">待发送</Radio>
                        <Radio label="1">已发送</Radio>
                        <Radio label="2">海关接收</Radio>
                        <Radio label="100">海关退单</Radio>
                        <Radio label="300">人工审核</Radio>
                        <Radio label="399">海关审结</Radio>
                        <Radio label="800">放行</Radio>
                        <Radio label="899">结关</Radio>
                        <Radio label="500">查验</Radio>
                        <Radio label="501">扣留移送通关</Radio>
                        <Radio label="502">扣留移送缉私</Radio>
                        <Radio label="503">扣留移送法规</Radio>
                        <Radio label="599">其它扣留</Radio>
                        <Radio label="700">退运</Radio>
                    </RadioGroup>
                </FormItem>
            </Row>
        </ISearch>
        <ITable :current="page.current" :table="table" :total="page.total" @on-page-change="pageChange">
            <template slot-scope="{ row, index }" slot="order_code">
                <span>{{row.order.code}}</span>
            </template>
            <template slot-scope="{ row, index }" slot="order_number">
                <span>{{row.order.number}}</span>
            </template>
            <template slot-scope="{ row, index }" slot="status">
                <span v-if="row.status === `0`">待发送</span>
                <span v-if="row.status === `1`">已发送</span>
                <span v-if="row.status === `2`">海关接收</span>
                <span v-if="row.status === `100`">海关退单</span>
                <span v-if="row.status === `300`">人工审核</span>
                <span v-if="row.status === `399`">海关审结</span>
                <span v-if="row.status === `800`">放行</span>
                <span v-if="row.status === `899`">结关</span>
                <span v-if="row.status === `500`">查验</span>
                <span v-if="row.status === `501`">扣留移送通关</span>
                <span v-if="row.status === `502`">扣留移送缉私</span>
                <span v-if="row.status === `503`">扣留移送法规</span>
                <span v-if="row.status === `599`">其它扣留</span>
                <span v-if="row.status === `700`">退运</span>
            </template>
            <template slot-scope="{ row, index }" slot="action">
                <Button size="small" @click="openComponent('IIView', {id: row.id})">查看</Button>
                <PoptipButton size="small" content="清关清关清关去了！~"
                              @on-ok="submitForAgain(row.id)">重推
                </PoptipButton>

            </template>
        </ITable>

        <component :is="componentProps.view" v-model="componentProps.value"
                   :props="componentProps.props"></component>
    </IContent>
</template>

<script>
    import contentListPage from "../../../mixins/contentListPage";
    import IContent from "../../../components/content/index";
    import ISearch from "../../../components/content/search";
    import ITable from "../../../components/content/table";
    import contentDrawer from "../../../mixins/contentDrawer";
    import RemoteSelect from "../../../components/form/remoteSelect";
    import PoptipButton from "../../../components/content/poptipButton";
    import IIView from "./view"

    export default {
        name: "index",
        components: {PoptipButton, RemoteSelect, ITable, ISearch, IContent, IIView},
        mixins: [contentListPage, contentDrawer],
        data() {
            return {
                table: {
                    columns: [
                        {
                            title: '仓单号',
                            slot: 'order_code',
                            width: 180
                        }, {
                            title: '订单号',
                            slot: 'order_number',
                            minWidth: 180
                        }, {
                            title: '状态',
                            slot: 'status',
                            width: 80
                        },
                        {
                            title: '清单号',
                            key: 'invt_no',
                            width: 200
                        },{
                            title: '预录入编号',
                            key: 'pre_no',
                            width: 200
                        },
                        {
                            title: '说明',
                            key: 'info',
                            minWidth: 280
                        }, {
                            title: '创建时间',
                            key: 'created_at',
                            minWidth: 100
                        },
                        {
                            title: '操作',
                            slot: 'action',
                            minWidth: 100
                        }
                    ]
                },
                search: {}
            }
        },
        methods: {
            submitForAgain(id) {
                this.loading = true;
                this.$http.put(`order/inventory/${id}`).then((data) => {
                    this.getLists(this.page.current)
                }).finally(() => {
                    this.loading = false;
                });
            },
            getLists(page) {
                this.loading = true;
                this.$http.get(`order/inventory`, {
                    params: Object.assign({}, this.search, {page: page})
                }).then((data) => {
                    this.table.data = data.data
                    this.page.total = data.total
                    this.page.current = data.current_page
                }).finally(() => {
                    this.loading = false;
                });
            }
        }
    }
</script>

<style scoped>

</style>
